﻿using System.Collections.Generic;
using System.Windows.Input;
using IndentationSplitter;
using unTroublemaker;

namespace unTroublemakerUI.ViewModel.DesignTime
{
    public class DesignTimeMainWindowViewModel : IMainWindowViewModel
    {
        public DesignTimeMainWindowViewModel()
        {
            SpecificationPath = @"C:\Program Files (x86)\Our Company\The application\Bin\Test specification.xml";
            //ErrorMessage = "Something is wrong with the xml";

            const string designTimeChecks = @"if value is something
                check-registry value is something
                check service is running
                if registry value is something
                    check-file exists here
                if registry value is something else
                    check-file is in this place
            if value is something else
                check-registry";

            SpecificationItems = SimpleTree.Parse<ISpecificationItemViewModel>(designTimeChecks, GetSpecItemViewModel);

            ItemCount = 15;
            ItemsProcessed = 5;
            IsRunning = true;
        }

        ISpecificationItemViewModel GetSpecItemViewModel(string displayName, IEnumerable<ISpecificationItemViewModel> children)
        {
            return new DesignTimeSpecificationItemViewModel(displayName, children);
        }

        public static IMainWindowViewModel Instance
        {
            get { return new DesignTimeMainWindowViewModel(); }
        }

        public IEnumerable<ISpecificationItemViewModel> SpecificationItems { get; set; }
        public ICommand RunCommand { get { return null; } }
        public ICommand BrowseCommand { get { return null; } }

        public string SpecificationPath { get; set; }
        public int ItemCount { get; set; }
        public int ItemsProcessed { get; set; }
        public bool IsRunning { get; set; }

        public string ErrorMessage { get; set; }
        public bool HasError { get { return !string.IsNullOrEmpty(ErrorMessage); } }
    }
}
